package java44th.group.controller.wx.address;

import java44th.group.bean.admin.vo.BaseRespVo;
import java44th.group.bean.po.MarketAddress;
import java44th.group.bean.po.MarketUser;
import java44th.group.bean.wx.vo.address.WxAddressListVo;
import java44th.group.bean.wx.vo.address.WxAddressVo;
import java44th.group.service.wx.address.WxAddressService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;

/**
 * @Aurhor: 王可龙
 * @DATE: 2022/10/14 23:17
 * @Package:java44th.group.controller.wx.address
 * @Description:
 * @Version 1.0
 */
@RestController
@RequestMapping("wx/address")
public class WxAddressController {

    @Autowired
    WxAddressService wxAddressService;

    @GetMapping("list")
    public BaseRespVo list(){
        MarketUser marketUser = (MarketUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        Integer userId = marketUser.getId();
        WxAddressListVo wxAddressListVo= wxAddressService.list(userId);
        return BaseRespVo.ok(wxAddressListVo);
    }
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){
        WxAddressVo wxAddressVo= wxAddressService.detail(id);
        return BaseRespVo.ok(wxAddressVo);
    }
    @RequestMapping("save")
    public BaseRespVo save(@RequestBody MarketAddress marketAddress){
        //获取当前用户的id
        MarketUser marketUser = (MarketUser) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
        Integer userId = marketUser.getId();
        Integer id= wxAddressService.save(marketAddress,userId);
        return BaseRespVo.ok(id);
    }


    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketAddress marketAddress){
        Integer id= wxAddressService.delete(marketAddress);
        return BaseRespVo.ok();
    }
}
